﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using br.com.SistemaChamados.Model;
using br.com.SistemaChamados.Enum;
using br.com.SistemaChamados.DAO;

namespace br.com.SistemaChamados.Controller
{
    public class UnitController
    {

        public EnumGenericState InsertUnit(Unit unit)
        {
            EnumGenericState stateTransaction = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                stateTransaction = UnitDAO.InsertUnit(unit);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return stateTransaction;
        }

        public EnumGenericState UpdateUnit(Unit unit)
        {
            EnumGenericState stateTransaction = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                stateTransaction = UnitDAO.UpdateUnit(unit);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return stateTransaction;
        }

        public EnumGenericState DeleteUnit(Unit unit)
        {
            EnumGenericState stateTransaction = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                stateTransaction = UnitDAO.DeleteUnit(unit);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return stateTransaction;
        }

        public Unit GetUnit(Unit unit)
        {
            Unit ValidateUnitSelected = new Unit();
            try
            {
                ValidateUnitSelected = UnitDAO.getUnit(unit);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ValidateUnitSelected;
        }

        public List<Unit> GetUnits()
        {
            List<Unit> Returnedlist = new List<Unit>();

            try
            {
                Returnedlist = UnitDAO.getUnits();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return Returnedlist;
        }
        
    }
}